Of object-oriented programming languages, the above described Smalltalk, Objective-C and some other languages determine object types (classes) dynamically, that is, when executing a program.
Generally, with such a processing mechanism, whose processing concept is as shown in FIG. 6, the source code SC of a program is first compiled into object code OC by an compiler 1, and the compiled object code OC is read and executed by an interpreter 2.
With such an object-oriented language in which types are determined dynamically, if a message is transmitted to an object asking it to do some corresponding to the message is present in the class to which the object belongs. If the corresponding method is present, the requested processing is executed by the interpreter 2 immediately, and if not, the same search is repeated in turn in the parent classes, the superclasses, and the processing is finally executed where the method is found. To transmit a message to an object thus is generally called message transmission. FIG. 7 shows the concept of message transmission for an object-oriented language and the mechanism of method-search executed by the interpreter 2, based on the transmitted message.
As shown in FIG. 7, if an object `anObject` Obj1 belongs to a class `Class1` C1, which is derived from its parent class `Class2` C2 and further the class `Class2` C2 has a class `ClassN` Cn as an ancestor (Here, if `ClassN` Cn is the immediate parent of `Class2` C2, the `Class2` C2 is the child class and the `Class1` C1 is the grandchild class of the class `ClassN` Cn. ), and if a message is transmitted to the object `anObject` Obj1, the interpreter 2 searches whether or not a method corresponding to the message is present in the predefined function table Tcl for the class `Class1` C1 to which the object `anObject` Obj1 receiving the message belongs. If a method corresponding to the message `message` is present in the function table Tcl of the class `Class1` C1, the interpreter executes the method, and if not, the method corresponding to the message `message` present. Thus, a search for the method is carried out by the interpreter 2 until the corresponding method is finally found and then the method is executed.
FIG. 8 shows an example of the above described source code SC and the object code OC, which is the result of compilation. FIG. 8 (a) shows an example segment of program for message transmission in Smalltalk, an example of an object-oriented system in which type is determined dynamically. The object code OC shown in FIG. 8 (b) is an example of the output from the compiler 1. In FIG. 8 (b), the actual object code (machine code) is shown by a nnemonic expression for convenience.
In the method `exampleMessage` shown in FIG. 8 (a), the source code ` anObject message` including a message to be transmitted to the object `anObject` is compiled into the following object code OC including steps.
1. Push the name of the object `anObject` and the message `message` onto the stack.
2. Call a special processing routine `lookup` for finding the method and copy the execution result `result` to the result `result`, as indicated by the
Return the value in `result` as the result of the method `exampleMessage` (as indicated by `rts` in FIG. 8 (b).
The compiled object code OC is then read and executed by the interpreter 2.
The calling mechanism wherein a method is searched when a program is executed and the type thereof is determined dynamically is generally called calling with dynamic binding (or calling with late binding). It is necessary and useful in realizing polymorphism wherein different types respond to the same message differently, but compared with calling with static binding (or calling with early binding), wherein the type is determined statically by the preparatory type-checking at compile time, the execution speed with calling with dynamic binding is low. If the priority of a program is execution speed, the burden of calling with dynamic binding at execution time is a significant problem.
As shown, for example, in the invention called `Message processing method in an object-oriented database control system` of Japanese unexamined patent publication No. Hei 2-231638 (1990), there are mechanisms wherein message processing speed is increased by combining calling with dynamic binding and calling with static binding, but they are intended for object-oriented languages such as Smalltalk which are dynamically type-determining and wherein the compiler itself is structured to increase the execution speed of the object code compiled from source code relating to a message transmission portion.